# 自定义异常
class LenError(Exception):
    def __str__(self):
        # 异常描述信息
        return '长度不合法'


#  语法:
# 抛出错误
# raise 类名()

username = input('username:')
try:
    if 6 <= len(username) <= 18:
        print('用户名合法')
    else:
        raise LenError()
except LenError as e:
    print(e)
